import  java.util.List;
public class MyQueue {
    //双向链表实现队列
    static class ListNode{
        public int val;
        public  ListNode prev;
        public  ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first = null;//队头
    public ListNode last = null;//队尾
    public int usedSize = 0;

    public void offer(int val){//尾插 -------入队
        ListNode node = new ListNode(val);
        if(isEmpty()){//如果链表为空
            first = last = node;//第一次插入
        }else{
            last.next = node;
            node.prev = last;
            last = last.next;
        }
        usedSize++;//每次放一个元素usedSize++;

    }

    public int poll(){//头删  ---  删除队头元素
        /*if(isEmpty()){
            return -1;
        }*/
        if(first == null){//如果队头为空
            return -1;
        }else{
            int val  = first.val;;
            first = first.next;
            if(first != null){
                first.prev = null;
            }
            usedSize--;
            return val;
        }
    }


    public int peek(){//获取队头元素
        if(first == null){//如果队头为空
            return -1;
        }else{
            return  first.val;//获取队头元素
        }

    }


    public boolean isEmpty(){//
        return  usedSize == 0;

    }



}
